package Framework.GuiElements
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.SimpleButton;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import Framework.BaseEventHandler;
	import Framework.BaseGui;

	/**
	 * ...
	 * @author Menno
	 */
	public class Button extends BaseGui
	{
		private var _x:uint;
		private var _y:uint;
		private var _xSize:uint;
		private var _ySize:uint;
		private var _text:String;
		private var _btnImage:Class;
		private var _image:Bitmap;
		private var _event:String;
		
		//private var _sprite:Sprite;
		
		public function Button(text:String, xSize:uint = 60, ySize:uint = 25, x:uint = 0, y:uint = 0,  image:Class = null) 
		{		
			_x = x;
			_y = y;		
			_xSize = xSize;
			_ySize = ySize;
			_text = text;
		
			_btnImage = image;
			
			if (image)
			{			
				_image = new image();
			}
			else
			{
				[Embed(source='GuiImages/button.png')]
				var img:Class;
				_image = new img();
			}
			
			createButton();
			
			this.x = _x;
			this.y = _y;
			
			super();
		}
		
		private function createButton():void
		{
			var textField:TextField = new TextField();
			
			textField.text = _text;
			textField.width = _xSize;
			textField.height = _ySize;
			textField.autoSize = "center";
			textField.selectable = false;
			textField.y = this.height / 2 - textField.textHeight / 2 - 5;
			//draw();
			
			addChild(_image);			
			addChild(textField);
		}

		/**
		 * Dit is bedoeld voor button animaties weergeven. 
		 */
		public function addButtonListener(eventString:String, eventHandler:BaseEventHandler):void
		{
			addEventListener(MouseEvent.MOUSE_UP, mouseUp, false, 0, true);
			addEventListener(MouseEvent.MOUSE_DOWN, mouseDown, false, 0, true);
			addEventListener(MouseEvent.CLICK, doClick, false, 0, true);
			
			_event = eventString;
			
			function mouseUp():void
			{			
				trace("lock")
			}
				
			function mouseDown():void
			{
				trace("klik");
			}			
		}
		
		private function doClick(e:MouseEvent):void 
		{
			BaseEventHandler.dispatcher.dispatchEvent(new Event(_event));
		}
				
		override public function draw():void
		{	
			_image.width = _xSize;
			_image.height = _ySize;
		}
		
		/**
		 * @private
		 * Sprite met button gegevens.
		 *
		public function get sprite():Sprite
		{
			return _sprite;
		}
		*/
		override public function get height():Number
		{
			return _ySize;			
		}
		override public function get width():Number
		{
			return _xSize;
		}

	}
}